/* poporca6.p - PURCHASE ORDER RECEIPT W/ SERIAL NUMBER CONTROL         */
/* Copyright 1986 QAD Inc. All rights reserved.                               */
/* $Id:: poporca6.p 15200 2012-02-23 20:06:30Z myb                         $: */
/*                                                                      */
/* REVISION: 7.3      LAST MODIFIED: 10/31/94   BY: WUG *GN77*          */
/* REVISION: 7.3      LAST MODIFIED: 02/28/95   BY: WUG *G0G2*          */
/* REVISION: 9.0      LAST MODIFIED: 04/16/99   BY: *J2DG* Reetu Kappor */
/* REVISION: 9.1      LAST MODIFIED: 11/17/99   BY: *N04H* Vivek Gogte  */
/* Old ECO marker removed, but no ECO header exists *F0PN*               */
/* REVISION: 9.1      LAST MODIFIED: 06/22/00   BY: *N0D7* B. Gates     */
/* REVISION: 9.1      LAST MODIFIED: 06/28/00   BY: Zheng Huang      *N0DK* */
/* REVISION: 9.1      LAST MODIFIED: 08/13/00   BY: *N0KQ* myb              */
/* $Revision: 1.15 $       BY: Julie Milligan   DATE: 03/04/05  ECO: *P32D* */
/*-Revision end---------------------------------------------------------------*/

/*V8:ConvertMode=NoConvert                                                    */
/* ADDED NO-UNDO AND REPLACED FIND STATEMENTS WITH FOR FIRST            */
/* STATEMENTS FOR ORACLE PERFORMANCE                                    */

/* CHECK NEW REPETITIVE CUM WO */
{us/bbi/mfdeclre.i}
/* SEVERITY PREPROCESSOR CONSTANT DEFINITION INCLUDE FILE */
{us/px/pxmaint.i}

define input parameter trans_type   as character no-undo.
define input parameter podnbr       as character no-undo.
define input parameter cumwo_lot    as character no-undo.
define input parameter op           as integer   no-undo.
define input parameter move         as logical   no-undo.

define     shared variable kbtransnbr      as integer no-undo.

define variable msg_ct               as integer  no-undo.


define variable qty_chg              as decimal  no-undo.
define variable input_que_op_to_ck   as integer  no-undo.
define variable input_que_qty_chg    as decimal  no-undo.

/* NO NEED TO PROCESS WORKORDER IF CALLED FROM KANBAN TRANSACTION PROCESSING */
if kbtransnbr <> 0 then leave.

 {us/px/pxrun.i &PROC='processRead' &PROGRAM='wowoxr.p'
          &PARAM="(input cumwo_lot,
                   buffer wo_mstr,
                   input {&NO_LOCK_FLAG},
                   input {&NO_WAIT_FLAG})"
 }

 if not available wo_mstr then leave.

 {us/px/pxrun.i &PROC='readOperationForFirstWOID' &PROGRAM='wowrxr.p'
               &PARAM="(input cumwo_lot,
                        input op,
                        buffer wr_route,
                        input {&NO_LOCK_FLAG},
                        input {&NO_WAIT_FLAG})"
 }

 if not available wr_route then leave.

 move = wr_mv_nxt_op.

 if not {us/px/pxfunct.i &FUNCTION='isRepetitiveProduction' &PROGRAM='rewoxr.p'
                   &PARAM="input wo_type,
                           input wo_nbr"
         }  then do:
     leave.
 end.

 {us/px/pxrun.i &PROC='validateSubcontractCost' &PROGRAM='wowrxr.p'
          &PARAM="(input wr_sub_cost)"
 }
 if return-value <> {&SUCCESS-RESULT} then
     msg_ct = msg_ct + 1.


 {us/px/pxrun.i &PROC='getQtyReceivedOnWO' &PROGRAM='porcxr1.p'
          &PARAM="(input podnbr,
                   input cumwo_lot,
                   input op,
                   output qty_chg)"
 }

 if trans_type = "return" then qty_chg = - qty_chg.

 /*DETERMINE INPUT QUE op TO CHECK; COULD BE PRIOR NONMILESTONES*/
 {us/bbi/gprun.i ""reiqchg.p"" "(input cumwo_lot,
                          input op,
                          input qty_chg,
                          output input_que_op_to_ck,
                          output input_que_qty_chg)"
 }

/*CHECK INPUT QUEUE*/
 {us/bbi/gprun.i ""rechkq.p"" "(input cumwo_lot,
                         input input_que_op_to_ck,
                         input ""i"",
                         input input_que_qty_chg,
                         input-output msg_ct)"
 }

/*CHECK OUTPUT QUEUE IF NOT move*/
if not move then do:
   {us/bbi/gprun.i ""rechkq.p"" "(input cumwo_lot,
                           input op,
                           input ""o"",
                           input qty_chg,
                           input-output msg_ct)"
   }
end.

if move then do:
   {us/px/pxrun.i &PROC='readNextOperationForWOID' &PROGRAM='wowrxr.p'
                  &PARAM="(input cumwo_lot,
                           input op,
                           buffer wr_route,
                           input {&NO_LOCK_FLAG},
                           input {&NO_WAIT_FLAG})"
   }

   if available wr_route then do:
      {us/bbi/gprun.i ""rechkq.p"" "(input cumwo_lot, input wr_op,
                              input ""i"",
                              input qty_chg,
                              input-output msg_ct)"
      }
   end.
end.


/*FORCE A PAUSE IF NECESSARY*/
{us/bbi/gprun.i ""repause.p"" "(input msg_ct)"}
